package com.chixing.ih.module.programmer.service.Impl;

import com.chixing.ih.module.programmer.mapper.PersonalSkillMapper;
import com.chixing.ih.module.programmer.pojo.PersonalSkill;
import com.chixing.ih.module.programmer.pojo.dto.PersonalSkillDTO;
import com.chixing.ih.module.programmer.service.IPersonalSkillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @version 1.0
 * @Author MasterYan
 * @Date 2020/10/3
 * Time: 10:38
 */
@Service
@Transactional
public class PersonalSkillServiceImpl implements IPersonalSkillService {

    @Autowired
    PersonalSkillMapper personalSkillMapper;

    @Override
    public boolean updateList(List<PersonalSkill> personalSkills) {
        for (PersonalSkill personalSkill : personalSkills
        ) {
            int record = personalSkillMapper.updateOne(personalSkill);
            if (record == 0)
                return false;
        }
        return true;

    }

    @Override
    public List<PersonalSkill> listAll(long userId) {
        List<PersonalSkill> personalSkillList = new ArrayList();
         List<Long> personalSkillIds = personalSkillMapper.getPersonalSkillId(userId);
        for (Long personalSkillId : personalSkillIds
        ) {
            PersonalSkill personalSkillMapperOne = personalSkillMapper.getOne(personalSkillId);
            personalSkillList.add(personalSkillMapperOne);

        }
        return personalSkillList;


    }

    @Override
    public PersonalSkill savePersonalSkill(PersonalSkillDTO personalSkillsDTO) {
        int record1 = personalSkillMapper.insertOne(personalSkillsDTO);
        personalSkillsDTO.setUserSkillId(personalSkillsDTO.getId());
        int record2 = personalSkillMapper.insert(personalSkillsDTO);
        PersonalSkill personalSkill = new PersonalSkill();
        personalSkill.setId(personalSkillsDTO.getId());
        if (record1 > 0 && record2 > 0)
            return personalSkill;
        return null;

    }

    @Override
    public boolean deletePersonalSkill(long id) {
        int record = personalSkillMapper.deleteOne(id);
        if (record <= 0)
            return false;
        return true;
    }
}
